import { Injectable } from '@angular/core';
import { BaseService } from './base.service';

@Injectable({
  providedIn: 'root'
})
export class CoreService extends BaseService {
  getMenu(orgid: string) {
    const url = 'api/menu';
    return this.get(url, {
      params: {
        orgId: orgid
      }
    });
  }
  async getLoginPageConfig(orgId: string) {
    let url = 'api/page';
    let r = await this.get(url, {
      params: {
        type: 'loginPage',
        orgId,
      }
    });

    return r.length ? r[0] : null;
  }

  getOrgInfo(orgId: string) {
    let url = 'api/organization/' + orgId;
    return this.get(url);
  }

  get org() {
    let r = localStorage.getItem('organization');
    if (r) {
      return JSON.parse(r);
    }
    else {
      return null;
    }
  }

  set org(data) {
    localStorage.setItem('organization', JSON.stringify(data));
  }
}
